<?php

namespace App\Repositories;

use App\Models\Orderinfo;

class OrderinfoRepository extends BaseRepository
{
    public function model()
    {
        return Orderinfo::class;
    }

    /**
     * 获取订单信息列表
     * Date: 2018/05/10
     * @param $service_id
     * @param $limit
     * @author Tenny
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function getOrderinfos($service_id = false, $limit = false)
    {
        $query = \DB::table('orderinfo_express as s');
        if ($service_id !== false) {
            $query->where('net.service_id', '=', $service_id);
        }
        $orderInfos = $query
            ->select(['net.designation orderinfo_name', 'ex.name as express_name ', 'net.address', 'net.name as owner_name', 'net.cover'])
            ->leftJoin('orderinfo as net', 's.service_id', '=', 'net.orderinfo_id')
            ->leftJoin('express_company as ex', 'ex.id', '=', 'net.express_id')
            ->where('s.service_id', '=', $service_id)
            ->orderBy('net.created_at', 'desc')
            ->orderBy('net.id', 'asc')
            ->paginate($limit);
        return $orderInfos;
    }

    protected function serialization(array $attributes)
    {
        // TODO: Implement serialization() method.
    }
}